/**
 *
 */
package com.bitrate.dagger.server.crawler.controller;

import com.bitrate.dagger.restful.response.ResponseResult;
import com.bitrate.dagger.server.crawler.service.CrawlerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/crawler-api")
@RestController
public class ApiCrawlerController {

    @Resource
    private CrawlerService crawlerService;

    @GetMapping("/execute/{category}")
    public ResponseResult<String> execute(@PathVariable(name = "category", required = true) String category) {
        crawlerService.execute(category);
        return ResponseResult.successNotice("抓取数据成功");
    }

    @GetMapping("/execute/article")
    public ResponseResult<String> executeArticle() {
        crawlerService.executeArticle(null);
        return ResponseResult.successNotice("抓取文章成功");
    }


    @GetMapping("/execute/article/{parentId}")
    public ResponseResult<String> executeArticleByParentId(@PathVariable(name = "parentId", required = true) Long parentId) {
        crawlerService.executeArticle(parentId);
        return ResponseResult.successNotice("抓取文章大纲成功");
    }


    @GetMapping("/execute/article/detail")
    public ResponseResult<String> executeArticleDetail() {
        crawlerService.executeArticleDetail();
        return ResponseResult.successNotice("抓取文章成功");
    }
}
